﻿using System.Data.Common;
using System.Data.SqlClient;

namespace EntityFrameworkVisualizer.VisualizerObjectSources.CommandFormatters
{
    /// <summary>
    /// Factory for DbCommandFormatter.
    /// </summary>
    internal static class DbCommandFormatterFactory
    {
        /// <summary>
        /// Creates new <see cref="IDbCommandFormatter"/>.
        /// </summary>
        /// <param name="command">Sql command.</param>
        /// <returns><see cref="IDbCommandFormatter"/>.</returns>
        public static IDbCommandFormatter Create(DbCommand command)
        {
            var commandType = command.GetType();

            if (commandType == typeof(SqlCommand))
            {
                return new SqlCommandFormatter((SqlCommand)command);
            }

            return new DefaultDbFormatter(command);
        }
    }
}
